package com.xiaohe66.web.timer.birth;

import com.xiaohe66.web.domain.birth.repository.BirthdayRepository;
import com.xiaohe66.web.domain.birth.service.BirthdayService;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author xiaohe
 * @since 2023.08.09 15:43
 */
@Component
@RequiredArgsConstructor
public class BirthTimer {

    private final BirthdayService birthdayService;
    private final BirthdayRepository birthdayRepository;

    /**
     * TODO : 暂时定为每天9点，未来需要改为按不同用户实现不同时间的推送
     */
    // @Scheduled(cron = "0 0 9 * * ?")
    public void pushBirthdayMessage() {

        birthdayService.pushBirthdayMessage();
    }

    @Scheduled(cron = "0 0 0 * * ?")
    public void updateNextBirth() {

        // TODO : 分布式的话，只让一个服务进行更新

        birthdayRepository.updateNextBirth();
    }
}
